package mabstract;

/**
 * @author Ajie
 * @date 2021-03-17
 * @function 测试抽象类
 */
public class AbstractDemo {

    public InnerClass innerClass = new InnerClass() {
        @Override
        void absfun() {
            System.out.println("全局变量持有的引用："+this);
        }
    };

    /**
     * @Description: 静态抽象内部类
     */
    static abstract class InnerClass {
        int i = 1;
        static int si = 2;
        //普通方法：fun()
        void fun() {
            System.out.println("内部方法");
        }
        //静态方法：sfun()
        static void sfun() {
            System.out.println("内部静态方法");
        }
        //抽象方法：absfun()
        abstract void absfun();
    }

    static class TestClass extends InnerClass {
        //内部实现方法
        @Override
        public void absfun() {
            System.out.println("内部实现方法");
        }
    }

    public static void main(String[] args) {
        InnerClass.sfun();
//        InnerClass innerClass = new InnerClass();
        TestClass testClass = new TestClass();
        testClass.absfun();
        testClass.fun();
        testClass.i = 2;
        testClass.si = 3;
        System.out.println(testClass.i);
        System.out.println(InnerClass.si);


        AbstractDemo abstractDemo = new AbstractDemo();
        abstractDemo.innerClass.i=4;
        System.out.println(abstractDemo.innerClass.i);

        abstractDemo.innerClass.i=5;
        System.out.println(abstractDemo.innerClass.i);

        abstractDemo.innerClass.absfun();

        System.out.println("全局变量：静态内部类的引用："+abstractDemo.innerClass);
        System.out.println("全局变量：静态内部类的引用："+abstractDemo.innerClass);
        System.out.println("对象："+abstractDemo);
        AbstractDemo abstractDemo2 = new AbstractDemo();
        abstractDemo2.innerClass.absfun();
    }
}
